<html layout:decorate="~{diagnostic/diagnostic_layout}" xmlns:layout="http://www.w3.org/1999/xhtml">
<body>
<div layout:fragment="content_diagnostic">
    <div class="main-body">
        <div style="float: right;margin-right: 10px;margin-bottom: 5px;">
            <a type="button" class="btn btn-primary btn-sm" style="margin-right: 10px;margin-bottom: 5px;"
               data-toggle="modal" href="/project/arithmeticManage/manage_add" data-target="#modal3">新增</a>

            <!--<a type="button" class="btn btn-info btn-sm" style="margin-right: 10px;margin-bottom: 5px;" data-toggle="modal" href="javascript:void(0)" data-target="#modal">编辑</a>-->
            <a type="button" class="btn btn-info btn-sm" style="margin-right: 10px;margin-bottom: 5px;"
              onclick="editData('/project/arithmeticManage/manage_edit','id')">编辑</a>

            <a type="button" class="btn btn-danger btn-sm" style="margin-right: 10px;margin-bottom: 5px;"
               onclick="delDatas('/project/arithmeticManage/manage_delete')">删除</a>

            <a type="button" class="btn btn-primary btn-sm" style="margin-right: 10px;margin-bottom: 5px;"
               data-toggle="modal" href="/diagnostic/algorithm_add" data-target="#modal">修改触发条件</a>
        </div>
        <table id="dataTable" data-url="/diagnostic/algorithm_data" data-page-list=[] data-striped="true"
               data-pagination="true" data-page-size="15" data-cache="false">
        </table>
    </div>


    <script>
        //table字段
        var dataFormat = [{
            checkbox: true
        }, {
            title: '序号',
            align: 'center',
            formatter: function (value, row, index) {
                return index + 1;
            }
        }, {
            field: 'name',
            title: '算法名称',
            align: 'center'
        }, {
            field: 'objName',
            title: '对象',
            sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return '项目';
                }
                if (value == 2) {
                    return '电池包';
                }
                if (value == 3) {
                    return '电池模组';
                }
                if (value == 4) {
                    return '变流器';
                }
                if (value == 5) {
                    return '电池单体';
                }
                if (value == 6) {
                    return '平台';
                }
            }
        }, {
            field: 'version',
            title: '版本',
            align: 'center'
        }, {
            field: 'updateTime',
            align: 'center',
            title: '部署时间',
            formatter: function (value, row, index) {
                if (value == null) {
                    return "";
                }
                return formatTimeStrap(value);
            }
        }, {
            field: 'remark',
            align: 'center',
            title: '备注'
        }, {
            field: 'touchCondition',
            align: 'center',
            title: '触发条件'
        }, {
            field: 'isReverseControl',
            align: 'center',
            title: '反向控制',
            formatter: formatControl
        }, /*{
                field: 'process',
                align: 'center',
                title: '控制工序'
            },{
                field: 'childAlgorithm',
                align: 'center',
                title: '子算法'
            },*/{
            field: 'isValid',
            align: 'center',
            title: '有效',
            formatter: formatStatus
        }];

        //状态格式化
        function formatStatus(value, row, index) {
            var html = '';
            if (value == 0) {
                html += '<input type="checkbox"/>';
            }

            if (value == 1) {
                html += '<input type="checkbox" checked="checked"/>';
            }

            return [html].join('');
        }

        //控制反转格式化
        function formatControl(value, row, index) {
            var html = '';
            if (value == 1) {
                html += '<p>是</p>';
            }
            return [html].join('');
        }

        //初始化table
        window.onload = function () {
            getTable(dataFormat, "dataTable");
        };
        //修改按钮
        function editData(url,field,id) {
            var idResult = "dataTable";
            if(id){
                idResult = id;
            }
            var table = $("#"+idResult).bootstrapTable('getSelections');
            if(table.length == 0){
                alert("请选择一条记录");
                return false;
            }else if(table.length > 1){
                alert("只能选择一条记录");
                return false;
            }
            var result = table[0][field];
            $("#modal3").modal({
                remote:url+ "?"+field+"="+result
            });
        }
    </script>
</div>
</body>
</html>